<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>子域名管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>子域名搜索</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">厂商</label>
                            <div class="layui-input-inline">
                                <input type="text" name="CusName" placeholder="请选择厂商" autocomplete="off"
                                       class="layui-input" id="CusNameSelect">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">子域名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="SubDomain" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">IP</label>
                            <div class="layui-input-inline">
                                <input type="text" name="IP" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">地区</label>
                            <div class="layui-input-inline">
                                <input type="text" name="Location" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                    lay-filter="data-search-btn"><i class="layui-icon"></i>
                                搜 索
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <script type="text/html" id="toolbarSubDomain">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm" lay-event="Refresh"><i class="layui-icon">&#xe666;</i>刷新</button>
            </div>
        </script>
        <table class="layui-hide" id="currentTable_SubDomain" lay-filter="currentTableFilter"></table>
    </div>
</div>
<script src="/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="/js/lay-config.js?v=2.0.0" charset="utf-8"></script>
<script>
    layui.use(['form', 'table', 'tableSelect'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            tableSelect = layui.tableSelect;

        table.render({
            elem: '#currentTable_SubDomain',
            url: "/api/scan/subdomain",
            toolbar: '#toolbarSubDomain',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '刷新',
                layEvent: 'Refresh',
                icon: 'layui-icon-refresh-3'
            }],
            cols: [
                [{
                    field: 'id',
                    width: 80,
                    title: 'ID',
                    sort: true
                },
                    {
                        field: 'cus_name',
                        width: 100,
                        title: '厂商'
                    },
                    {
                        field: 'subdomain',
                        width: 200,
                        title: '子域名',
                        sort: true
                    },
                    {
                        field: 'ip',
                        width: 160,
                        title: 'ip'
                    },
                    {
                        field: 'location',
                        width: 260,
                        title: '地区'
                    },
                    {
                        field: 'cdn',
                        title: 'CDN',
                        width: 100,
                        templet:function(d){
                            if (d.cdn){
                                d.cdn = "是";
                            }else{
                                d.cdn = "否";
                            }
                            return d.cdn;
                        },
                    },
                    {
                        field: 'cname',
                        title: 'CNAME',
                        width: 120
                    },
                    {
                        field: 'flag',
                        title: '扫描状态',
                        width: 160,
                        templet:function(d){
                            if (d.flag){
                                d.flag = "已扫描";
                            }else{
                                d.flag = "未扫描";
                            }
                            return d.flag;
                        },
                    },
                    {
                        field: 'nsq_flag',
                        title: '投递状态',
                        width: 160,
                        templet:function(d){
                            if (d.nsq_flag){
                                d.nsq_flag = "已投递";
                            }else{
                                d.nsq_flag = "未投递";
                            }
                            return d.nsq_flag;
                        },
                    },
                    {
                        field: 'create_at',
                        title: '时间',
                        minWidth: 500
                    },

                ]
            ],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            //执行搜索重载
            table.reload('currentTable_SubDomain', {
                page: {
                    curr: 1
                },
                where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });

        tableSelect.render({
            elem: '#CusNameSelect',
            checkedKey: 'id',
            searchPlaceholder: '厂商搜索',
            searchKey: 'cusname',
            table: {
                url: '/api/scan/group/cusname',
                cols: [[
                    {type: 'radio', title: "选择"},
                    {field: 'id', width: 60, title: 'ID'},
                    {field: 'cus_name', title: '厂商'},
                    {field: 'cus_remark', title: '备注'},
                ]]
            },
            done: function (elem, data) {
                var NEWJSON = []
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.cus_name)
                })
                elem.val(NEWJSON.join(","))
            }
        })

        // 刷新
        table.on('toolbar(currentTableFilter)', function (obj) {
            if(obj.event === 'Refresh'){
                table.reload('currentTable_SubDomain', {
                    page: {
                        curr: 1
                    }
                    ,
                }, 'data');
            }
        });

    });
</script>

</body>
</html>